function [Yp] = mcdqsvm(X,Y,ktype,C)
[n,d] = size(X);
l = size(Y,1);

cls = unique(Y);
c = size(cls,1);
np =c*(c-1)/2;

sz = zeros(c,1);
idx = cell(c,1);
for i = 1:c
    idx{i}=find(Y==cls(i));
    sz(i)=size(idx{i},1);
end

VM = zeros(n-l,np);

Xs = X(l+1:end,:);

ct = 1;
for i = 1:c
    for j = i+1:c
        disp(['Training pair ',int2str(i),' vs ',int2str(j)]);
        ix = [idx{i};idx{j}];
        Xt = X(ix,:);
        Yt = [ones(sz(i),1);-ones(sz(j),1)];
        if (nargin == 2)
            [VM(:,ct)] = dqsvm([Xt;Xs],Yt,ktype);
        else
            [VM(:,ct)] = dqsvm([Xt;Xs],Yt,ktype,C);
        end
        ct = ct+1;
    end
end

vot = zeros(n-l,c);

ct = 1;
for i = 1:c
    for j = i+1:c
        vot(:,i) = vot(:,i)+(VM(:,ct)>0);
        vot(:,j) = vot(:,j)+(VM(:,ct)<0);
        ct=ct+1;
    end
end
[~,Yc] = max(vot,[],2);
Yp = cls(Yc);
end